<template>
  <div style="position: relative;">
    <el-form ref="ContractListFilter" :model="ContractList" :size="defaultFormItemSize"
             label-width="100px" label-position="right" @submit.native.prevent>
      <filter-box :item-width="350">
        <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                   @click="onResetContractList">重置</el-button>
        <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                   @click="refreshContractList(true)">查询</el-button>
        <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                   @click="onContractFormClick">新增</el-button>
      </filter-box>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table ref="contract" :data="ContractList.Contract.impl.dataList" :size="defaultFormItemSize"
                  @sort-change="ContractList.Contract.impl.onSortChange"
                  header-cell-class-name="table-header-gray">
          <el-table-column label="序号" header-align="center" align="center" type="index"
                           width="55px" :index="ContractList.Contract.impl.getTableIndex">
          </el-table-column>
          <el-table-column label="项目" prop="projectIdDictMap.name"></el-table-column>
          <el-table-column label="合同编号" prop="no"></el-table-column>
          <el-table-column label="合同名称" prop="name"></el-table-column>
          <el-table-column label="施工单位" prop="constructionOrgDictMap.name"></el-table-column>
          <el-table-column label="监理单位" prop="supervisorOrg"></el-table-column>
          <el-table-column label="简称" prop="shorthand"></el-table-column>
          <el-table-column label="状态" prop="state"></el-table-column>
          <el-table-column label="项目可用" prop="enableFlag"></el-table-column>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <el-button @click.stop="onContractFormEditClick(scope.row)" type="text"
                         :size="defaultFormItemSize">编辑</el-button>
              <el-button @click.stop="onDeleteClick(scope.row)" type="text" :size="defaultFormItemSize">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination
            :total="ContractList.Contract.impl.totalCount"
            :current-page="ContractList.Contract.impl.currentPage"
            :page-size="ContractList.Contract.impl.pageSize"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            @current-change="ContractList.Contract.impl.onCurrentPageChange"
            @size-change="ContractList.Contract.impl.onPageSizeChange">
          </el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { findTreeNode, findTreeNodePath, findItemFromList } from '@/utils';
  import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
  import { uploadMixin, statsDateRangeMixin, cachePageMixin } from '@/core/mixins';
  import { ContractInfoController, DictionaryController } from '@/api';
  import contractForm from '@/views/myOrg/contractForm.vue';
    export default {
        name: "contractList",
      props: {
      },
      mixins: [uploadMixin, statsDateRangeMixin, cachePageMixin],
      data () {
          return {
            ContractList: {
              formFilter: {
                id: undefined,
                projectId: undefined,
                type: undefined,
                no: undefined,
                code: undefined,
                name: undefined,
                constructionOrg: undefined,
                principal: undefined,
                supervisorOrg: undefined,
                startPileNo: undefined,
                endPileNo: undefined,
                roadLength: undefined,
                contractPrice: undefined,
                contractSign: undefined,
                start: undefined,
                planEnd: undefined,
                planFinish: undefined,
                bankName: undefined,
                bankAccountName: undefined,
                bankAccount: undefined,
                state: undefined,
                shorthand: undefined,
                fixMeasureAmount: undefined,
                enableFlag: undefined
              },
              formFilterCopy: {
                id: undefined,
                projectId: undefined,
                type: undefined,
                no: undefined,
                code: undefined,
                name: undefined,
                constructionOrg: undefined,
                principal: undefined,
                supervisorOrg: undefined,
                startPileNo: undefined,
                endPileNo: undefined,
                roadLength: undefined,
                contractPrice: undefined,
                contractSign: undefined,
                start: undefined,
                planEnd: undefined,
                planFinish: undefined,
                bankName: undefined,
                bankAccountName: undefined,
                bankAccount: undefined,
                state: undefined,
                shorthand: undefined,
                fixMeasureAmount: undefined,
                enableFlag: undefined
              },
              Contract: {
                impl: new TableWidget(this.loadContractListWidgetData, this.loadContractVerify, true, false, 'id', 0)
              },
              projectId: {
                impl: new DropdownWidget(this.loadProjectIdDropdownList),
              },
              isInit: false
            }
          }
      },
      methods: {
          onResetContractList () {
            this.$refs.ContractListFilter.resetFields();
            this.refreshContractList(true);
          },
        /**
         * 数据获取函数，返回Promise
         */
        loadContractListWidgetData (params) {
            if (params == null) params = {};
            params = {
              ...params,
              sysContractInfoDtoFilter: {
                id: this.ContractList.formFilterCopy.id,
                projectId: this.ContractList.formFilterCopy.projectId,
                type: this.ContractList.formFilterCopy.type,
                no: this.ContractList.formFilterCopy.no,
                code: this.ContractList.formFilterCopy.code,
                name: this.ContractList.formFilterCopy.name,
                constructionOrg: this.ContractList.formFilterCopy.constructionOrg,
                principal: this.ContractList.formFilterCopy.principal,
                supervisorOrg: this.ContractList.formFilterCopy.supervisorOrg,
                startPileNo: this.ContractList.formFilterCopy.startPileNo,
                endPileNo: this.ContractList.formFilterCopy.endPileNo,
                roadLength: this.ContractList.formFilterCopy.roadLength,
                contractPrice: this.ContractList.formFilterCopy.contractPrice,
                contractSign: this.ContractList.formFilterCopy.contractSign,
                start: this.ContractList.formFilterCopy.start,
                planEnd: this.ContractList.formFilterCopy.planEnd,
                planFinish: this.ContractList.formFilterCopy.planFinish,
                bankName: this.ContractList.formFilterCopy.bankName,
                bankAccountName: this.ContractList.formFilterCopy.bankAccountName,
                bankAccount: this.ContractList.formFilterCopy.bankAccount,
                state: this.ContractList.formFilterCopy.state,
                shorthand: this.ContractList.formFilterCopy.shorthand,
                fixMeasureAmount: this.ContractList.formFilterCopy.fixMeasureAmount,
                enableFlag: this.ContractList.formFilterCopy.enableFlag
              }
            };
          return new Promise((resolve, reject) => {
            ContractInfoController.list(this, params).then(res => {
              resolve({
                dataList: res.data.dataList,
                totalCount: res.data.totalCount
              });
            }).catch(e => {
              reject(e);
            });
          });
        },

        /**
         * 数据获取函数，返回Promise
         */
        loadContractVerify () {
            this.ContractList.formFilterCopy.id = this.ContractList.formFilter.id ;
            this.ContractList.formFilterCopy.projectId = this.ContractList.formFilter.projectId ;
            this.ContractList.formFilterCopy.type = this.ContractList.formFilter.type ;
            this.ContractList.formFilterCopy.no = this.ContractList.formFilter.no ;
            this.ContractList.formFilterCopy.code = this.ContractList.formFilter.code ;
            this.ContractList.formFilterCopy.name = this.ContractList.formFilter.name ;
            this.ContractList.formFilterCopy.constructionOrg = this.ContractList.formFilter.constructionOrg ;
            this.ContractList.formFilterCopy.principal = this.ContractList.formFilter.principal ;
            this.ContractList.formFilterCopy.supervisorOrg = this.ContractList.formFilter.supervisorOrg ;
            this.ContractList.formFilterCopy.startPileNo = this.ContractList.formFilter.startPileNo;
            this.ContractList.formFilterCopy.endPileNo = this.ContractList.formFilter.endPileNo;
            this.ContractList.formFilterCopy.roadLength = this.ContractList.formFilter.roadLength;
            this.ContractList.formFilterCopy.contractPrice = this.ContractList.formFilter.contractPrice;
            this.ContractList.formFilterCopy.contractSign = this.ContractList.formFilter.contractSign;
            this.ContractList.formFilterCopy.start = this.ContractList.formFilter.start;
            this.ContractList.formFilterCopy.planEnd = this.ContractList.formFilter.planEnd;
            this.ContractList.formFilterCopy.planFinish = this.ContractList.formFilter.planFinish;
            this.ContractList.formFilterCopy.bankName = this.ContractList.formFilter.bankName;
            this.ContractList.formFilterCopy.bankAccountName = this.ContractList.formFilter.bankAccountName;
            this.ContractList.formFilterCopy.bankAccount = this.ContractList.formFilter.bankAccount;
            this.ContractList.formFilterCopy.state = this.ContractList.formFilter.state;
            this.ContractList.formFilterCopy.shorthand = this.ContractList.formFilter.shorthand;
            this.ContractList.formFilterCopy.fixMeasureAmount = this.ContractList.formFilter.fixMeasureAmount;
            this.ContractList.formFilterCopy.enableFlag = this.ContractList.formFilter.enableFlag;
            return true;

        },
        /**
         * 更新表页
         */
        refreshContractList (reloadData = false) {
          if (reloadData) {
            this.ContractList.Contract.impl.refreshTable(true, 1);
          } else {
            this.ContractList.Contract.impl.refreshTable();
          }
          if (!this.ContractList.isInit) {
            // 初始化下拉数据
          }
          this.ContractList.isInit = true;
        },
        /**
         * 新增
         */
        onContractFormClick () {
          let params = {};
          this.$dialog.show('新增',contractForm, {
            area: '800px'
          },params).then(res => {
            this.refreshContractList();
          }).catch(e => {});
        },
        /**
         * 编辑
         */
        onContractFormEditClick (row) {
          let params = {
            id: row.contractId
          };
          this.$dialog.show('编辑',ContractForm, {
            area: '800px'
          },params).then(res => {
            this.ContractList.Contract.impl.refreshTable();
          }).catch(e => {});
        },
        /**
         * 删除
         */
        onDeleteClick (row) {
          let params = {
            id : row.contractId
          };
          ContractInfoController.delete(this,params).then(res => {
            this.$message.success('删除成功');
            this.ContractList.Contract.impl.refreshTable(false,1);
          }).catch(e => {});
        },
        /**
         * 选中值改变
         */
        onProjectIdValueChange (value) {
          this.formData.Contract.sectionId = undefined;
          this.ContractList.contractId.impl.dirty = true;
          this.onContractIdValueChange(this.formData.Contract.sectionId);
        },
        /**
         * 项目id下拉数据获取函数
         */
        loadProjectIdDropdownList () {
          return new Promise((resolve, reject) => {
            let params = {};
            DictionaryController.dictSysProject(this, params).then(res => {
              resolve(res.getList());
            }).catch(e => {
              reject(e);
            });
          });
        },
        onResume () {
          this.refreshContractList();
        },
        initFormData () {

        },
        formInit () {
          this.refreshContractList();
        }
      },
      mounted () {
        this.formInit();
      },
      watch: {}

    }
</script>

<style scoped>

</style>
